package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqTuan;
import com.ruoyi.wq.service.IWqTuanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 拼团Controller
 * 
 * @author ruoyi
 * @date 2023-08-28
 */
@RestController
@RequestMapping("/wq/tuan")
public class WqTuanController extends BaseController {

    @Autowired
    private IWqTuanService wqTuanService;

    /**
     * 查询团购列表
     */
    @Anonymous
    @GetMapping("/getList")
    public TableDataInfo getList(WqTuan wqTuan){
        TableDataInfo info = wqTuanService.getPageList(wqTuan);
        return info;
    }

    /**
     * 导出拼团列表
     */
    @PreAuthorize("@ss.hasPermi('wq:tuan:export')")
    @Log(title = "拼团", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqTuan wqTuan)
    {
        List<WqTuan> list = wqTuanService.selectWqTuanList(wqTuan);
        ExcelUtil<WqTuan> util = new ExcelUtil<WqTuan>(WqTuan.class);
        util.exportExcel(response, list, "拼团数据");
    }

    /**
     * 获取拼团详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:tuan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqTuanService.selectWqTuanById(id));
    }

    /**
     * 新增拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:tuan:add')")
    @Log(title = "拼团", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WqTuan wqTuan)
    {
        return toAjax(wqTuanService.insertWqTuan(wqTuan));
    }

    /**
     * 修改拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:tuan:edit')")
    @Log(title = "拼团", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqTuan wqTuan)
    {
        return toAjax(wqTuanService.updateWqTuan(wqTuan));
    }

    /**
     * 删除拼团
     */
    @PreAuthorize("@ss.hasPermi('wq:tuan:remove')")
    @Log(title = "拼团", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqTuanService.deleteWqTuanByIds(ids));
    }
}
